#ifndef __MAIN_PAGE_H__
#define __MAIN_PAGE_H__

#include <list>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <stdexcept> // 包含标准异常类
#include "page.h"
#include "dish.h"
#include "dish_type.h"
#include "mfont.h"
#include "bmp.h"
#include "shop_dish.h"

#define DISH_TYPE_BUTTON ((235<=(x)&&(x)<=790)&&(15<=(y)&&(y)<=55))
#define EXPLOSIVE_PACKAGE_BUTTON ((235<=(x)&&(x)<=330)&&(15<=(y)&&(y)<=55))
#define NANCHANG_MIXED_RICE_NOODLES_BUTTON ((350<=(x)&&(x)<=445)&&(15<=(y)&&(y)<=55))
#define CLAY_POT_SOUP_BUTTON ((465<=(x)&&(x)<=560)&&(15<=(y)&&(y)<=55))
#define NANCHANG_SNACKS_BUTTON ((580<=(x)&&(x)<=675)&&(15<=(y)&&(y)<=55))
#define BEVERAGE_BUTTON ((695<=(x)&&(x)<=790)&&(15<=(y)&&(y)<=55))

#define PREV_NEXT_PAGE_BUTTON ((400<=(x)&&(x)<=770)&&(430<=(y)&&(y)<=470))
#define PREV_PAGE_BUTTON ((400<=(x)&&(x)<=550)&&(430<=(y)&&(y)<=470))
#define NEXT_PAGE_BUTTON ((625<=(x)&&(x)<=770)&&(430<=(y)&&(y)<=470))

#define DISH_MINUS_ADD_BUTTON_UP ((110<=(x)&&(x)<=780)&&(200<=(y)&&(y)<=230))
#define DISH_MINUS_BUTTON_1   ((110<=(x)&&(x)<=145)&&(200<=(y)&&(y)<=230))
#define DISH_ADD_BUTTON_1     ((155<=(x)&&(x)<=190)&&(200<=(y)&&(y)<=230))
#define DISH_MINUS_BUTTON_2   ((305<=(x)&&(x)<=340)&&(200<=(y)&&(y)<=230))
#define DISH_ADD_BUTTON_2     ((350<=(x)&&(x)<=385)&&(200<=(y)&&(y)<=230))
#define DISH_MINUS_BUTTON_3   ((500<=(x)&&(x)<=535)&&(200<=(y)&&(y)<=230))
#define DISH_ADD_BUTTON_3     ((545<=(x)&&(x)<=580)&&(200<=(y)&&(y)<=230))
#define DISH_MINUS_BUTTON_4   ((695<=(x)&&(x)<=730)&&(200<=(y)&&(y)<=230))
#define DISH_ADD_BUTTON_4     ((740<=(x)&&(x)<=775)&&(200<=(y)&&(y)<=230))

#define DISH_MINUS_ADD_BUTTON_DOWN ((110<=(x)&&(x)<=780)&&(380<=(y)&&(y)<=410))
#define DISH_MINUS_BUTTON_5   ((110<=(x)&&(x)<=145)&&(380<=(y)&&(y)<=410))
#define DISH_ADD_BUTTON_5     ((155<=(x)&&(x)<=190)&&(380<=(y)&&(y)<=410))
#define DISH_MINUS_BUTTON_6   ((305<=(x)&&(x)<=340)&&(380<=(y)&&(y)<=410))
#define DISH_ADD_BUTTON_6     ((350<=(x)&&(x)<=385)&&(380<=(y)&&(y)<=410))
#define DISH_MINUS_BUTTON_7   ((500<=(x)&&(x)<=535)&&(380<=(y)&&(y)<=410))
#define DISH_ADD_BUTTON_7     ((545<=(x)&&(x)<=580)&&(380<=(y)&&(y)<=410))
#define DISH_MINUS_BUTTON_8   ((695<=(x)&&(x)<=730)&&(380<=(y)&&(y)<=410))
#define DISH_ADD_BUTTON_8     ((740<=(x)&&(x)<=775)&&(380<=(y)&&(y)<=410))

#define ORDER_BUTTON          ((215<=(x)&&(x)<=290)&&(430<=(y)&&(y)<=470))



enum class Dish_Type_E {
    Explosive_package,
    Nanchang_mixed_rice_noodles,
    clay_pot_soup,
    Nanchang_snacks,
    beverage
};

enum class Page_Type_E {
    Prev_page,
    Next_page 
};

class MainPage: public Pages{
private:
    //系统初始化时候的所有菜的信息
    std::list<DishType> dish_type_list;
    
    //界面的八个位置的数组
    std::vector<Dish> dish_vector;

    //页数
    int m_page_num;

    //总价格
    int m_totle_price;

    //购物车链表
    std::list<ShopDish> m_shopping_cart;

public:
    MainPage(int width = 0, int height = 0, int page_num = 1, int totle_price = 0);
    // //展示主页面
    // void display();
    //生成菜品信息链表
    void lists_init();
    //第一次进入界面时 菜名，价格的初始化
    void dish_name_price_init();
    void lists_show();
    
    //1点击上方菜种类的按钮
    void dish_type_click(Dish_Type_E type);

    //2把链表中要的数据存到vector中
    int dish_vector_init(Dish_Type_E flag, int page_num);

    //3把vector<Dish>数据显示到界面上
    void dish_vector_show(int i);

    //点击下方上一页下一页的按钮
    void prev_next_click(Dish_Type_E dish_type, Page_Type_E page_type);

    //点击+号，把对应位置的菜的信息添加到购物车链表中
    void add_to_shopping_cart(int i);

    //点击-号，把购物车中对应位置的菜的数量-1，为0就移除
    void minus_from_shopping_cart(int i);

    //计算购物车中所有菜的总金额
    void totle_price_calculate();

    int get_total_price();

    //将总金额显示到界面上
    void totle_price_show();

    //点击下单按钮，把购物车数据以及总金额输出到后台
    void order_click();

    //点完下单后，清空购物车数据以及总金额置为0
    void order_clear();
    
    ~MainPage();
};


#endif